home *** CD-ROM | disk | FTP | other *** search
- ;void input_right(col,row,color,max_len,char_case,return_strg);
- ; unsigned short col,row,color,max_len;
- ; char char_case,*ret_strg;
-
- EXTRN _memory_model:byte
- EXTRN _error_code:byte
- EXTRN _beep_on:byte
-
- _TEXT SEGMENT BYTE PUBLIC 'CODE'
- ASSUME CS:_TEXT
- PUBLIC _input_right
- _input_right proc near
- mov _error_code,1 ;1 = parameter out of range
- push bp ;
- mov bp,sp ;set up stack frame
- push di ;
- push si ;
- cmp _memory_model,0 ;near or far?
- jle begin ;jump if near
- inc bp ;else add 2 to BP
- inc bp ;
- begin: cmp _memory_model,2 ;data near or far?
- jb A0 ;jump if near
- les di,dword ptr[bp+14] ;point ES:DI to return string
- jmp short A00 ;jump ahead
- A0: mov ax,ds ;move DS to ES
- mov es,ax ;
- mov di,[bp+14] ;
- A00: mov byte ptr es:[di],0 ;clear descriptor in case error
- sub al,al ;clear AL
- mov dl,[bp+4] ;col to DL
- dec dl ;count from 0
- cmp dl,79 ;in range?
- jna B1 ;jump ahead if so
- A1: jmp U1 ;else quit
- B1: mov dh,[bp+6] ;row to DH
- dec dh ;count from 0
- cmp dh,24 ;in range?
- ja A1 ;quit if not
- mov bl,[bp+8] ;attribute to BL
- sub bh,bh ;page 0
- mov al,[bp+10] ;max string length to AL
- or al,al ;test for zero length
- jz A1 ;quit if zero
- dec _error_code ;0 = no error
- mov ah,[bp+12] ;character case to AH
- mov bp,di ;let BP point to string
- mov di,ax ;store both in DI
- mov ah,2 ;function to set cursor
- int 10h ;set the cursor
- sub si,si ;SI points to ret string
- sub al,al ;initial string length
- mov es:[bp],al ;set the descriptor
- C1: inc si ;forward string pointer
- D1: mov cx,1 ;num chars to write
- sub ah,ah ;func to read keystroke
- int 16h ;wait for keystroke
- cmp al,0 ;test for extended code
- jne E1 ;jump if not extended
- cmp ah,83 ;is it the Del key?
- jne D1 ;next keystroke if not
- jmp short I1 ;else jmp to backspc code
- E1: cmp al,13 ;test for carriage return
- jne F1 ;jump ahead if not CR
- jmp S1 ;else quit routine
- F1: cmp al,27 ;test for Escape
- jne H1 ;jump ahead if not Escape
- mov cl,es:[bp] ;string length to CX
- or cl,cl ;test for null string
- je D1 ;ignore keystroke if null
- mov es:[bp],ch ;zero out strg length
- sub si,si ;clear string pointer
- sub dl,cl ;col pos - string length
- G1: inc dl ;inc cursor column
- mov ah,2 ;function to set cursor
- int 10h ;reset the cursor
- mov al,32 ;erase with spc character
- push cx ;save strg len counter
- mov cx,1 ;number chars to write
- mov ah,9 ;function to write char
- int 10h ;erase a char
- pop cx ;restore counter
- loop G1 ;go erase next char
- jmp short C1 ;go get next keystroke
- H1: cmp al,8 ;test for backspace
- jne J1 ;jump ahead if not bkspc
- I1: cmp es:[bp],ch ;start of string?
- je K1 ;go beep, get next key
- sub es:[bp],cl ;dec string descriptor
- dec si ;dec string pointer
- push dx ;save cursor position
- mov ax,si ;string length to AX
- sub dl,al ;subtract from cursor pos
- inc dl ;back one column
- mov ah,2 ;function to set cursor
- int 10h ;reset cursor
- pop dx ;restore prior cursor pos
- mov al,32 ;erase with space char
- mov ah,9 ;function to write char
- int 10h ;erase a char
- cmp si,1 ;single char left?
- je D1 ;no need to rewrite line
- jmp short Q1 ;else go rewrite line
- J1: cmp al,32 ;some other ctrl code?
- jb D1 ;skip it if so
- push dx ;test right margin...
- sub dh,dh ;DX = col position
- inc dx ;adjust
- cmp si,dx ;line length equals?
- pop dx ;restore row/col
- jnbe K1 ;skip char, beep
- xchg di,cx ;fetch MaxLen
- cmp es:[bp],cl ;comp to strg descriptor
- xchg di,cx ;restore CX
- jne L1 ;jump if string not full
- K1: push dx ;save cursor setting
- mov ah,2 ;DOS func to write char
- mov dl,7 ;bell character
- cmp _beep_on,0 ;test whether beep enabled
- je K2 ;jump if not
- int 21h ;beep!
- K2: pop dx ;restore cursor setting
- jmp D1 ;go get next keystroke
- L1: xchg cx,di ;move case type to CH
- cmp ch,'u' ;upper case?
- je M1 ;jump if so
- cmp ch,'U' ;upper case?
- jne N1 ;jump ahead if not
- M1: cmp al,'a' ;below 'a'?
- jb P1 ;move on if out of range
- cmp al,'z' ;above 'z'?
- ja P1 ;move on if out of range
- sub al,32 ;convert to upper case
- jmp short P1 ;go write it
- N1: cmp ch,'l' ;lower case?
- je O1 ;jump if so
- cmp ch,'L' ;lower case?
- jne P1 ;no adjustment if not
- O1: cmp al,'A' ;below 'A'?
- jb P1 ;move on if out of range
- cmp al,'Z' ;above 'Z'?
- ja P1 ;move on if out of range
- add al,32 ;convert to upper case
- P1: xchg cx,di ;restore CX count
- mov es:[bp][si],al ;set keystroke for return
- add es:[bp],cl ;inc string descriptor
- Q1: mov cl,es:[bp] ;string length to CX
- sub dl,cl ;cursor col-number chars
- sub si,si ;point SI to descriptor
- R1: inc dl ;forward cursor position
- mov ah,2 ;function to set cursor
- int 10h ;reset the cursor
- push cx ;save strg len counter
- mov cx,1 ;number chars to write
- inc si ;inc string pointer
- mov al,es:[bp][si] ;get char to write
- mov ah,9 ;function to write char
- int 10h ;write the char
- pop cx ;restore strg len counter
- loop R1 ;go write next char
- jmp C1 ;go get next character
- S1: sub cx,cx ;convert to C string
- mov cl,es:[bp] ;get string length
- or cl,cl ;test for zero length
- jz U1 ;quit if null string
- T1: mov al,es:[bp+1] ;get a char
- mov es:[bp],al ;shift downward
- inc bp ;forward ptr
- loop T1 ;move whole string
- mov byte ptr es:[bp],0 ;terminating byte
- U1: pop si ;
- pop di ;
- pop bp ;
- cmp _memory_model,0 ;quit
- jle quit ;
- db 0CBh ;RET far
- quit: ret ;RET near
- _input_right ENDP
- _TEXT ENDS
- END